package com.aaa.controller;

import com.aaa.entity.TabUser;
import com.aaa.service.ITabUserRoleService;
import com.aaa.service.ITabUserService;
import com.aaa.util.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 于永利
 * @since 2024-08-03
 */
@RestController
@RequestMapping("/tab-user")

public class TabUserController {

    @Autowired
    private ITabUserService tabUserService;


    @Autowired
    private ITabUserRoleService userRoleService;

    @GetMapping
    // 查询所有的员工的信息
    public Result queryAll(Integer currentPage, Integer pageSize){
        IPage page =new Page(currentPage,pageSize);

        return Result.success(tabUserService.page(page));

    }


    @PostMapping
    public Result addUser(@RequestBody TabUser user){


        //
        tabUserService.saveOrUpdate(user);// 存了用户的信息
        //System.out.println(user.getId());
        // 用户的id    user。getId()

        // 角色的ids     user.getPermissions()
        //
        userRoleService.saveUserRoles(user.getPermissions(),user.getId());

        return Result.success("uuu");
    }

}
